import request from '@/config/axios'
import { MicroServicePrefix } from '@/api/base/model'

export interface ResourceVO {
  kind: string
  name: string
  parentId?: number
  code: string
  path?: string
  route: string
  iconCss?: string
  sort: number
}

// 查询菜单（精简）列表
export const getSimpleMenusList = () => {
  return request.get({ url: '/system/menu/simple-list' })
}

// 查询菜单列表
export const getMenuList = (memberUid: string, params) => {
  return request.get({ url: `${MicroServicePrefix.FACILITIES}/menu/navigation/${memberUid}`, params })
}

// 获取菜单详情
export const getMenu = (id: number) => {
  return request.get({ url: `${MicroServicePrefix.FACILITIES}/menu/${id}` })
}

// 新增菜单
export const createMenu = (data: ResourceVO) => {
  return request.post({ url: `${MicroServicePrefix.FACILITIES}/menu`, data })
}

// 修改菜单
export const updateMenu = (id: number, data: Omit<ResourceVO, 'kind'>) => {
  return request.put({ url: `${MicroServicePrefix.FACILITIES}/menu/${id}`, data })
}

// 删除菜单
export const deleteMenu = (id: number) => {
  return request.delete({ url: `${MicroServicePrefix.FACILITIES}/menu/${id}` })
}

// 获取页面详情
export const getPage = (id: number) => {
  return request.get({ url: `${MicroServicePrefix.FACILITIES}/page/${id}` })
}

// 新增页面
export const createPage = (data: ResourceVO) => {
  return request.post({ url: `${MicroServicePrefix.FACILITIES}/page`, data })
}

// 修改页面
export const updatePage = (id: number, data: Omit<ResourceVO, 'kind'>) => {
  return request.put({ url: `${MicroServicePrefix.FACILITIES}/page/${id}`, data })
}

// 删除页面
export const deletePage = (id: number) => {
  return request.delete({ url: `${MicroServicePrefix.FACILITIES}/page/${id}` })
}

// 获取操作详情
export const getOperation = (id: number) => {
  return request.get({ url: `${MicroServicePrefix.FACILITIES}/operation/${id}` })
}

// 新增操作
export const createOperation = (data: ResourceVO) => {
  return request.post({ url: `${MicroServicePrefix.FACILITIES}/operation`, data })
}

// 修改操作
export const updateOperation = (id: number, data: Omit<ResourceVO, 'kind'>) => {
  return request.put({ url: `${MicroServicePrefix.FACILITIES}/operation/${id}`, data })
}

// 删除操作
export const deleteOperation = (id: number) => {
  return request.delete({ url: `${MicroServicePrefix.FACILITIES}/operation/${id}` })
}
